/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.ucue.ptc.gco.ui;

import edu.ucue.ptc.gco.mdl.Categoria;
import edu.ucue.ptc.gco.mdl.Ciudad;
import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Marcelo
 */
@FacesConverter(value = "CiudadConverter")
@SessionScoped
public class CiudadConverter implements Converter, Serializable {
    
    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == "") {
            return null;
        }
        // Convert ProjectDetail to its unique String representation.
        Ciudad obj = (Ciudad) value;
        String idAsString = String.valueOf(obj.getIdCiudad());
        return idAsString;
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        // Convert unique String representation of ProjectDetail back to ProjectDetail object.
        Integer id;
        try {
            id = Integer.valueOf(value);
        } catch(Exception e) {
            return null;
        }
        
        Ciudad obj = new Ciudad();//delegacionManager.findDelegacion(id);
        obj.setIdCiudad(id);
        return obj;
    }
}